package com.eliteams.quick4j.app.controller;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import com.eliteams.quick4j.app.model.LogData;
import com.eliteams.quick4j.app.model.LogInfo;
import com.eliteams.quick4j.app.model.LogUUid;
import com.eliteams.quick4j.app.model.Sitemaprsslist;
import com.eliteams.quick4j.app.model.UuId;
import com.eliteams.quick4j.app.service.LogInfoService;
import com.eliteams.quick4j.app.service.LogUUidService;
import com.eliteams.quick4j.app.service.SitemaprssListService;
import com.eliteams.quick4j.app.service.impl.RedisService;
import com.eliteams.quick4j.core.entity.SiteMapUtils;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import redis.clients.jedis.Jedis;

/**
 * Created by Administrator on 2017/11/15.
 */
@Controller
@RequestMapping("/site")
public class SiteprssListController extends SiteMapUtils {
	private static Log logger1 = LogFactory.getLog("mylogger1");
    private static Log logger2 = LogFactory.getLog("mylogger2");
    private static final Logger logger = LoggerFactory.getLogger(SiteprssListController.class);
    @Resource
    private SitemaprssListService sitemaprssListService;

    @Resource
	private RedisService redisService;
    
    @Resource
    private LogUUidService logUUidService;
    
    @Resource
    private LogInfoService logInfoService;
    
/*    @Resource
    private RedisAPI redisAPI;
*/  
    @Scheduled(cron="0 0 11,23 * * ?")//每天的11点、23点都执行一次
    public void testTime1(){//每隔12小时执行一次 0 * */12 * * ?
    	/*Date date = new Date();
    	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	String string = format.format(date);
    	System.out.println("每隔12小时执行一次 当前的时间："+string);*/
    	
    	selectSiteMap1();
    	readHtmlToRedis();
    	selectRSS();
    }
    
    @Scheduled(cron="0 0 8 * * ?")//每天8点执行一次
    public void testTime2(){
    	/*Date date = new Date();
    	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	String string = format.format(date);
    	System.out.println("每天10点执行一次 当前的时间："+string);*/
    	loginfo();
    }
    
    
    /**
     * 读取log日志存放数据库
     * @param response
     */
//    @RequestMapping(value="/loginfo",method=RequestMethod.POST)
    public void loginfo(){
    	long pointer=0;
    	Calendar cal=Calendar.getInstance();
    	cal.add(Calendar.DATE,-1);
    	Date time=cal.getTime();
    	String yesterday = new SimpleDateFormat("yyyy-MM-dd").format(time);
    	//根据时间进行模糊查询
    	List<LogUUid> listuuid = logUUidService.selectByCreateTime();
    	File tmpLogFile = new File("D://test/log."+yesterday+".log");
    	if(tmpLogFile == null) {  
    		//throw new IllegalStateException("logFile can not be null");  
    		return;
    	}else{
    		long len = tmpLogFile.length();  
    		try {
    			if(len < pointer){  
    				pointer = 0;  
    			}else{
    				//指定文件可读可写  
    				RandomAccessFile  randomFile= new RandomAccessFile(tmpLogFile,"rw");
    				randomFile.seek(pointer);
    				String tmp = "";  
    				while((tmp = randomFile.readLine()) != null) {  
    					String obj = new String(tmp.getBytes("UTF-8"));
    					try {
    						for(LogUUid logUUid_:listuuid){
    							String uuid_ = logUUid_.getUuid();
    							if((obj.indexOf(uuid_) != -1 && obj.indexOf("http://") != -1)|| (obj.indexOf(uuid_) != -1 && obj.indexOf("https://") != -1)){
    								String[] split = obj.split(" ");
    								String uuid = split[6];
    								//根据UUID查对应的ID
    								LogUUid objId = logUUidService.selectByUuid(uuid);
    								LogInfo record = new LogInfo();
    								record.setLogTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(split[3]+" "+split[4]));
    								record.setUrl(split[7]);
    								record.setLoguuidId(objId.getId());
    								record.setInformation(split[8]);
    								logInfoService.insertSelective(record);//存库
    							}else if(obj.indexOf(uuid_) != -1){
    								String[] split = obj.split(" ");
    								String uuid = split[6];
    								//根据UUID查对应的ID
    								LogUUid objId = logUUidService.selectByUuid(uuid);
    								LogInfo record = new LogInfo();
    								record.setLogTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(split[3]+" "+split[4]));
    								record.setLoguuidId(objId.getId());
    								record.setInformation(split[7]);
    								logInfoService.insertSelective(record);//存库
    							}
    						}
    						System.out.println("finish");
    					} catch (ParseException e) {
    						e.printStackTrace();
    					}
    					pointer = randomFile.getFilePointer();  
    				}
    				randomFile.close();
    			}
    		} catch (FileNotFoundException e) {
    			e.printStackTrace();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    }

    /**
     * 对某个时间段的log日志进行统计
     * 例子：2017-12-06 15:00:00至2017-12-06 17:00:00的数据汇总
     */
    @ResponseBody
    @RequestMapping(value="/logSummary",method=RequestMethod.POST)
    public void logSummary(HttpServletResponse response,HttpServletRequest request,
    		@RequestParam(value="startTime",required=false)String startTime,@RequestParam(value="endTime",required=false)String endTime){
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    	Date startDate;
    	Date endDate;
    	List<LogInfo>list=null;
    	List<LogData> dataList = new ArrayList<LogData>();
		try {
			startDate = sdf.parse(startTime);
			endDate = sdf.parse(endTime);
			//查询任务 id
			list = logInfoService.selectByTimeSlot(startDate,endDate);
			if(!list.isEmpty()){
				for(LogInfo lis : list){
					Integer loguuidId = lis.getLoguuidId();
					//查询任务的状态
					String stat = logInfoService.selectStatus(new LogInfo(loguuidId, "end"));
					String status;
					if(stat.equals("1")){
						status = "已完成";
					}else{
						status = "未完成";
					}
					//查询UUID
					LogUUid logUUid = logUUidService.selectByPrimaryKey(loguuidId);
					String uUid = logUUid.getUuid();//任务-UUID
					Integer type = logUUid.getType();//类型 :sitemap、rss
					Date createTime = logUUid.getCreateTime();//日志创建的时间
					//查任务对应的总数量
					int sum = logInfoService.selectSumCount(loguuidId);
					//查询任务对应的新数据
					int newData = logInfoService.selectByNewData(new LogInfo(loguuidId, "inserted"));
					//已存在的数据
					int oldData = sum - newData;
					dataList.add(new LogData(status, uUid, type, sdf.format(createTime), sum, newData, oldData));
				}
			}
			JSONArray a = JSONArray.fromObject(dataList);
			System.out.println(a);
			response.addHeader("Access-Control-Allow-Origin", "*");
            response.setContentType("application/json;charset=utf-8");
			response.getWriter().write(a.toString());
			response.getWriter().flush();
			response.getWriter().close();
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    /**
     * 查询
     */
    @RequestMapping(value = "/siteList", method= RequestMethod.POST)
    public void selectMemberList(HttpServletResponse resp,HttpServletRequest req){
        resp.addHeader("Access-Control-Allow-Origin", "*");
        resp.setContentType("application/json;charset=utf-8");
        String jsonStr = req.getParameter("value");
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        String startPage = jsonObject.get("start").toString();
        int start = Integer.parseInt(startPage);
        int size = 10;
        int startData = (start-1)*size;

        sitemaprssListService.fomartReturnJsonSiteView(req, resp, startData,size);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/addSite", method= RequestMethod.POST)
    public void addSite(HttpServletRequest req, HttpServletResponse resp){
        String jsonStr = req.getParameter("value");
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);

        Sitemaprsslist s = new Sitemaprsslist();
        s.setName(jsonObject.get("name").toString());
        s.setUrl(jsonObject.get("url").toString());
        s.setType(jsonObject.get("type").toString());
        s.setDd(jsonObject.get("Dd").toString());
        sitemaprssListService.insertSelective(s);
    }

    /**
     * 通过当前的id获取要修改的数据
     */
    @RequestMapping(value = "{id}/siteToUpdate", method= RequestMethod.POST)
    public void siteToUpdate(@PathVariable String id, HttpServletResponse resp, HttpServletRequest req){
        resp.addHeader("Access-Control-Allow-Origin", "*");
        resp.setContentType("application/json;charset=utf-8");
        Integer id1 = Integer.parseInt(id);
        Sitemaprsslist s = sitemaprssListService.selectByPrimaryKey(id1);
        JSONObject jo  = new JSONObject();
        jo.put("id",s.getId());
        jo.put("name",s.getName());
        jo.put("url",s.getUrl());
        jo.put("type",s.getType());
        jo.put("Dd",s.getDd());
        try {
            //后台输出测试
            System.out.println(jo.toString());
            //设置字符集
            req.setCharacterEncoding("UTF-8");
            //页面输出
            resp.getWriter().write(jo.toString());
            resp.getWriter().flush();
            resp.getWriter().close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }

    /**
     * 通过id修改当前的数据
     */
    @RequestMapping(value = "/siteUpdate", method= RequestMethod.POST)
    public void siteUpdate(HttpServletResponse resp, HttpServletRequest req){
        resp.addHeader("Access-Control-Allow-Origin", "*");
        resp.setContentType("application/json;charset=utf-8");
        String jsonStr = req.getParameter("value");
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        Integer id = Integer.parseInt(jsonObject.get("name").toString());
        String name = jsonObject.get("name").toString();
        String url = jsonObject.get("url").toString();
        String type = jsonObject.get("url").toString();
        String Dd = jsonObject.get("Dd").toString();
        Sitemaprsslist s = new Sitemaprsslist();
        s.setId(id);
        s.setName(name);
        s.setUrl(url);
        s.setType(type);
        s.setDd(Dd);
        sitemaprssListService.updateSiteById(s);
        sitemaprssListService.selectByPrimaryKey(id);

    }

    /**
     * 删除
     */
    @RequestMapping(value = "{id}/siteDelete", method= RequestMethod.POST)
    public void siteDelete(@PathVariable String id, HttpServletResponse resp, HttpServletRequest req){
        resp.addHeader("Access-Control-Allow-Origin", "*");
        resp.setContentType("application/json;charset=utf-8");
        Integer id1 = Integer.parseInt(id);
        sitemaprssListService.deleteByPrimaryKey(id1);
    }



    /**
     * 通过id删除redis相应的数据
     */
    @RequestMapping(value = "{id}/rssDel", method= RequestMethod.POST)
    public void rssDel(@PathVariable String id,HttpServletResponse resp, HttpServletRequest req) throws Exception{
        resp.addHeader("Access-Control-Allow-Origin", "*");
        resp.setContentType("application/json;charset=utf-8");
        Integer id1 = Integer.parseInt(id);
        Sitemaprsslist s = sitemaprssListService.selectByPrimaryKey(id1);
        URL url = new URL(s.getUrl());
        URLConnection rulConnection = url.openConnection();
        HttpURLConnection httpUrlConnection = (HttpURLConnection) rulConnection;
        httpUrlConnection.setRequestProperty("User-Agent",
                "Mozilla/31.0 (compatible; MSIE 7.0; Windows NT 5.1)");
        httpUrlConnection.connect();
        // 读取Rss源
        XmlReader reader = new XmlReader(httpUrlConnection);
        logger2.info("Rss源的编码格式为：" + reader.getEncoding());
        SyndFeedInput input = new SyndFeedInput();
        // 得到SyndFeed对象，即得到Rss源里的所有信息
        SyndFeed feed = input.build(reader);
        // 得到Rss新闻中子项列表
        List entries = feed.getEntries();
        for (int i = 0; i < entries.size(); i++) {
            SyndEntry entry = (SyndEntry) entries.get(i);
            UuId u = new UuId();
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("url",entry.getLink());
            String uuid;
            String uuid1 = u.post(jsonObject);
            JSONObject jsonObject1 = JSONObject.fromObject(uuid1);
            uuid = jsonObject1.get("uuid").toString();
//            redisAPI.del(uuid,5);
        }
        System.out.println("程序结束");
    }

    /**
     * 查看一级SiteMap数据
     */
	public void selectSiteMap1() {
		String uuId = SiteMapUtils.getUUid();// 标记日志的UUID
		LogUUid record = new LogUUid();
    	record.setUuid(uuId);
    	record.setType(1);
		//把UUID放到库里
    	logUUidService.insertSelective(record);
		List<String> siteMap1 = sitemaprssListService.selectSiteMap1(uuId);
		UuId u = new UuId();
		JSONObject jsonObject = new JSONObject();
		if (!siteMap1.isEmpty()) {
			logger1.info(" "+uuId+" start");
			for (String url : siteMap1) {
				if (!url.isEmpty()) {
					jsonObject.put("url", url);
					String uuid1 = u.post(jsonObject);
					JSONObject jsonObject1 = JSONObject.fromObject(uuid1);
					String uuid = jsonObject1.get("uuid").toString();
					if (redisService.exists(uuid) == true) {
						logger1.info(" "+uuId+" " + url + " existed");
						continue;
					} else {
						// 存放Redis缓存数据库中
						Jedis jedis11 = new Jedis("10.0.0.30",6389,1000000);
						jedis11.auth("Pa88####");
						jedis11.select(4);
						if(!jedis11.exists(uuid)){
							redisService.set(uuid, url);
    						logger1.info(" "+uuId+" "+url+" inserted");
						}else{
							logger1.info(" "+uuId+" " + url + " existed");
						}
					}
				}
			}
			logger1.info(" "+uuId+" end");
		}
	}   
    
    /**
     * 查看二级SiteMap数据<用下面的方法>
     * 1.把请求的连接的数据存放起来
     * 2.获取本地数据放Redis里
     */
	/*@RequestMapping(value = "/selectSiteMap2", method = RequestMethod.POST)
	public void selectSiteMap2(RedirectAttributes attr) {
		String uuId = SiteMapUtils.getUUid();// 标记日志的UUID
		  LogUUid record = new LogUUid(); 
		  record.setUuid(uuId);
		  record.setType(1); 
		  //把UUID放到库里
		  logUUidService.insertSelective(record);
		Set<String> set = new HashSet<String>();
		List<Sitemaprsslist> siteMap = sitemaprssListService.selectSiteMap();
		if (!siteMap.isEmpty()) {
			for (Sitemaprsslist sitemaprsslist : siteMap) {
				String url_ = sitemaprsslist.getUrl();
				logger1.info(" " + uuId + " " + url_ + " start");
				if (!url_.isEmpty()) {
					SiteMapUtils.getXMLs(url_, uuId);
					logger1.info(" " + uuId + " " + url_ + " success");
				} else {
					logger1.info(" " + uuId + " " + url_ + " is_empty");
				}
			}
		}
		// 遍历文件
		String u = "E:\\testsitemap\\";
		SAXReader reader1 = new SAXReader();
		File file = new File(u);
		File[] files = null;
		if (file.exists()) {
			files = file.listFiles();
			if (files[files.length - 1].isDirectory()) {
				logger1.info(" " + uuId + " " + files[files.length - 1].getAbsolutePath() + " folder");
			} else {
				logger1.info(" " + uuId + " " + files[files.length - 1].getAbsolutePath() + " start");// 获取每个文件路径
				// 读取文件 转换成Document
				Document document;
				Element rootElement;
				Element fooElement;
				UuId uu = new UuId();
				JSONObject jsonObject = new JSONObject();
				try {
					document = reader1.read(new File(files[files.length - 1].getAbsolutePath()));
					rootElement = document.getRootElement();
					for (Iterator i = rootElement.elementIterator("url"); i.hasNext();) {
						fooElement = (Element) i.next();
						String htmls_ = fooElement.elementText("loc");
						if (!set.contains(htmls_)) {// 判断是否已经存在，不存在才转换uuid存Redis中
							set.add(htmls_);
							jsonObject.put("url", htmls_);
							String uuid1 = uu.post(jsonObject);
							JSONObject jsonObject1 = JSONObject.fromObject(uuid1);
							String uuid = jsonObject1.get("uuid").toString();
							if (redisService.exists(uuid) == true) {
								logger1.info(" " + uuId + " " + htmls_ + " existed");
								continue;
							} else {
								// 存放Redis缓存数据库中
								redisService.set(uuid, htmls_);
								logger1.info(" " + uuId + " " + htmls_ + " inserted");
							}
							if (redisService.exists(uuid) == true) {
								logger1.info(" " + uuId + " " + htmls_ + " existed");
								continue;
							} else {
								// 存放Redis缓存数据库中
								Jedis jedis11 = new Jedis("10.0.0.30", 6389, 1000000);
								jedis11.auth("Pa88####");
								jedis11.select(4);
								if (!jedis11.exists(uuid)) {
									redisService.set(uuid, htmls_);
									logger1.info(" " + uuId + " " + htmls_ + " inserted");
								}
							}
						}
					}
				} catch (DocumentException e) {
					logger1.info(" " + uuId + " " + e);
				}
				logger1.info(" " + uuId + " " + files[files.length - 1].getAbsolutePath() + " success");
			}
		} else {
			logger1.info(" " + uuId + " unexist");
		}
	}*/
    
    /**
     * 查看二级SiteMap数据 haodf
     * 定时12小时执行一次
     * @param response
     */
//    @RequestMapping(value="/readHtmlToRedis",method=RequestMethod.POST)
    public  void readHtmlToRedis(){
    	String uuId = SiteMapUtils.getUUid();// 标记日志的UUID
    	LogUUid record = new LogUUid(); 
    	record.setUuid(uuId);
    	record.setType(1); 
    	//把UUID放到库里
    	logUUidService.insertSelective(record);
    	
    	List<Sitemaprsslist> siteMap = sitemaprssListService.selectSiteMap();
    	if (!siteMap.isEmpty()) {
    		logger1.info(" " + uuId + " start");
    		for (Sitemaprsslist sitemaprsslist : siteMap) {
    			String url_ = sitemaprsslist.getUrl();
    			if (!url_.isEmpty()) {
    				SiteMapUtils.getXMLs(url_, uuId);
    				//logger1.info(" " + uuId + " " + url_ + " success");
    			} else {
    				logger1.info(" " + uuId + " " + url_ + " is_empty");
    			}
    		}
    	}
    	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    	String date = df.format(new Date());
    	String[] split = date.split("-");
    	String s = "";
    	for (String string : split) {
    		s+=string;
    	}
    	if(String.valueOf(s.charAt(4)).equals("0") && String.valueOf(s.charAt(6)).equals("0")){//月与日是一位数就拆分
    		s=s.substring(0, 4)+s.substring(5,4+1+1)+s.substring(4+1+1+1);
    	}else if(String.valueOf(s.charAt(4)).equals("0")){
    		s=s.substring(0, 4)+s.substring(4+1);
    	}else if(String.valueOf(s.charAt(6)).equals("0")){
    		s=s.substring(0, 6)+s.substring(6+1);
    	}
    	UuId uu = new UuId();
    	JSONObject jsonObject = new JSONObject();
    	try{
    		String file = "E:\\testsitemap\\"+s+"1.xml";
    		DocumentBuilderFactory dbf =DocumentBuilderFactory.newInstance();
    		DocumentBuilder docBuilder = dbf.newDocumentBuilder();
    		org.w3c.dom.Document doc = docBuilder.parse(new File(file));
    		NodeList nodes = ((org.w3c.dom.Document) doc).getElementsByTagName("url");
    		for(int i=0;i<nodes.getLength();i++){
    			Node node = nodes.item(i);
    			NodeList childNodes = node.getChildNodes();
    			for(int j=0;j<childNodes.getLength();j++){
    				Node childNode = childNodes.item(j);
    				if(childNode.getNodeType() == Node.ELEMENT_NODE && childNode.getNodeName().equals("loc")){
    					String nodeValue = childNode.getFirstChild().getNodeValue();
    					
    					jsonObject.put("url", nodeValue);
    					String uuid1 = uu.post(jsonObject);
    					JSONObject jsonObject1 = JSONObject.fromObject(uuid1);
    					String uuid = jsonObject1.get("uuid").toString();
    					if (redisService.exists(uuid) == true) {
    						logger1.info(" " + uuId + " " + nodeValue + " existed");
    						continue;
    					} else {
    						// 存放Redis缓存数据库中
    						redisService.set(uuid, nodeValue);
    						logger1.info(" " + uuId + " " + nodeValue + " inserted");
    					}
    				}
    			}
    		}
    		logger1.info(" " + uuId + " end");
    	}catch(Exception e){
    		logger1.info(" "+ uuId+" "+e);
    	}
    }
    
    /**
     * 通过查询rss数据插入redis缓存
     */
//    @RequestMapping(value="/selectRSS",method=RequestMethod.POST)
    public void selectRSS(){
    	String uuId = SiteMapUtils.getUUid();// 标记日志的UUID
    	LogUUid record = new LogUUid();
    	record.setUuid(uuId);
    	record.setType(2);
    	//把UUID放到库里
    	logUUidService.insertSelective(record);
    	List<Sitemaprsslist> list = sitemaprssListService.selectRSS();
    	if(!list.isEmpty()){
    		logger1.info(" "+uuId+" start");
    		for (Sitemaprsslist rss : list) {
    			String strUrl = rss.getUrl();
    			URL url = null;
    			URLConnection rulConnection = null;
    			XmlReader reader = null;
    			SyndFeedInput input = new SyndFeedInput();
    			SyndFeed feed = null;
    			try {
    				url = new URL(strUrl);
    				rulConnection = url.openConnection();
    				HttpURLConnection httpUrlConnection = (HttpURLConnection) rulConnection;
    				httpUrlConnection.setRequestProperty("User-Agent",
    						"Mozilla/31.0 (compatible; MSIE 7.0; Windows NT 5.1)");
    				httpUrlConnection.connect();
    				reader = new XmlReader(httpUrlConnection);
    				feed = input.build(reader);
    			} catch (MalformedURLException e) {
    				logger1.info(" "+ uuId+" "+e);
    			} catch (IOException e) {
    				logger1.info(" "+ uuId+" "+e);
    			} catch (IllegalArgumentException e) {
    				logger1.info(" "+ uuId+" "+e);
    			} catch (FeedException e) {
    				logger1.info(" "+ uuId+" "+e);
    			}
    			// 得到Rss新闻中子项列表
    			List entries = feed.getEntries();
    			for (int i = 0; i < entries.size(); i++) {
    				SyndEntry entry = (SyndEntry) entries.get(i);
    				UuId u = new UuId();
    				JSONObject jsonObject = new JSONObject();
    				jsonObject.put("url",entry.getLink());
    				String uuid;
    				String uuid1 = u.post(jsonObject);
    				JSONObject jsonObject1 = JSONObject.fromObject(uuid1);
    				uuid = jsonObject1.get("uuid").toString();
    				if (redisService.exists(uuid) == true) {
    					logger1.info(" "+uuId+" "+entry.getLink()+" existed");
    					continue;
    				} else {
    					//存放Redis缓存数据库中
//                				redisService.set(uuid, entry.getLink());
//        						logger1.info(" "+uuId+" "+entry.getLink()+" inserted");
    					Jedis jedis11 = new Jedis("10.0.0.30",6389,1000000);
    					jedis11.auth("Pa88####");
    					jedis11.select(4);
    					if(!jedis11.exists(uuid)){
    						redisService.set(uuid, entry.getLink());
    						logger1.info(" "+uuId+" "+entry.getLink()+" inserted");
    					}
    				}
    			}
    			logger1.info(" "+uuId+" "+strUrl+" success");
    		}
    		logger1.info(" "+uuId+" end");
    	}
    }
}
